import { axios } from '@/utils/request'

const prefix = '/baseMaterials'


/**
 * 高级查询
 * @param params
 * @returns {AxiosPromise}
 */
export function superPageFetchList(params) {
  return axios({
    url: prefix + '/select',
    method: 'get',
    params:{
      ...params
    }
  })
}


/**
 * 新增
 * @param params
 * @returns {AxiosPromise}
 */
export function addObj(materials,prices,units) {
  return axios({
    url: prefix + '/add',
    method: 'POST',
    data: {
      "baseMaterials":materials,
      "baseMaterialsPrices":prices,
      "baseUnitConversions":units
    }
  })
}

/**
 * 删除
 * @param id
 * @returns {AxiosPromise}
 */
export function delObj(id) {
  return axios({
    url: prefix + '/delMaterialsById',
    method: 'get',
    params:{id:id}
  })
}
/**
 * 获取详情材料设备
 * @param id
 * @returns {AxiosPromise}
 */

export function getObj(id) {
  return axios({
    url: prefix + '/getInfoById',
    method: 'GET',
    params:{id:id}
  })
}
/**
 * 根据材料设备id获取价格
 * @param id
 * @returns {AxiosPromise}
 */

export function getPriceObj(params) {
  return axios({
    url: 'baseMaterialsPrice/selectAll',
    method: 'GET',
    data:{
      ...params
    }
  })
}
export function getUnitObj(params) {
  return axios({
    url: 'baseUnitConversions/selectAll',
    method: 'GET',
    data:{
      ...params
    }
  })
}

/**
 * 获取客户编码
 * @param id
 * @returns {AxiosPromise}
 */
export function getCode() {
  return axios({
    url: prefix + '/getCode',
    method: 'GET'
  })
}


/**
 * 修改
 * @param params
 * @returns {AxiosPromise}
 */
export function putObj(materials,prices,units) {
  for (let i =0;i<prices.length;i++){
    prices[i].id = null
  }
  for (let i =0;i<units.length;i++){
    units[i].id = null
  }
  return axios({
    url: prefix + '/update',
    method: 'post',
    data: {
      baseMaterials:materials,
      baseMaterialsPrices:prices,
      baseUnitConversions:units
    }
  })
}

/**
 * 获取材料设备类别
 * @returns {*}
 */
export function getMaterialsCategory(){
  return axios({
    url: 'baseMaterialsCategory/dropDown',
    method: 'get',
  })
}
export function getSupplierCode() {
  return axios({
    url: 'baseSuppliers/dropDown',
    method: 'get',
  })
}
/**
 * 下载模板
 * @returns {AxiosPromise}
 */
export function downloadExcelCandidate() {
  return axios({
    url: prefix + '/downloadExcelCandidate',
    method: 'get',
    responseType: 'arraybuffer'
  })
}
/**
 * 导出
 * @param params
 * @returns {*}
 */
export function exportData(params) {
  return axios({
    url: prefix + `/downloadExcel`,
    method: 'GET',
    params: params,
    responseType: 'blob'
  })
}
export function getUnit() {
  return axios({
    url: 'baseSuppliers/dropDown',
    method: 'get',
  })
}

/**
 * 查看所选物料的可用单位
 * @param materialCode
 * @returns {AxiosPromise}
 */
export function getUnitsByMaterialCode(materialCode) {
  return axios({
    url: '/baseUnitConversions/getUnitsByMaterialCode/' + materialCode,
    method: 'GET'
  })
}